#include "stdafx.h"
#include "RunTimeLib.h"

void MyInvalidParameterHandler(const wchar_t* express, const wchar_t* function, const wchar_t* filename, unsigned int line, uintptr_t)
{
	wchar_t buf[1024] = {0};
	swprintf(buf, 1024, L"InvalidParameter:express = %s, functionName = %s, filename = %s, line = %d", express, function, filename, line);
	MessageBoxW(NULL, buf, L"InvalidParameter", MB_ABORTRETRYIGNORE);
}

ShareApi void SetInvalidParameterHandler()
{
	_set_invalid_parameter_handler(&MyInvalidParameterHandler);
}

void MyPureCallHandler()
{
	MessageBoxW(NULL, L"Call pure virtual function", L"PureCall", MB_ABORTRETRYIGNORE);
}

ShareApi void SetPureCallHandler()
{
	_set_purecall_handler(&MyPureCallHandler);
}

ShareApi void DisplayError(int error)
{
	if(error == -1)
		error = GetLastError();
	char buf[1024] = {0};
	int offset = sprintf(buf, "ErrorID = %d\n", error);
	FormatMessageA(FORMAT_MESSAGE_FROM_SYSTEM, 0, error, MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US), buf + offset, 1024 - offset, 0);
	MessageBoxA(NULL, buf, "SystemError", MB_OK);
	__asm{int 3};
}
